package com.lx.huimailf.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.google.gson.Gson;

import com.lx.huimailf.MyApplication;
import com.lx.huimailf.R;
import com.lx.huimailf.configs.Config;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;


public class ForgetPasswordnextActivity extends Activity {

	private EditText mima;
	private EditText mima1;
	private Button finish;
	private LinearLayout fanhui;
	private String xiaoyanma="";
	private String phone="";
	private CheckBox auto_login;
	public static Activity instance;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setContentView(R.layout.activity_forget_passwordnext);
		instance=this;
		fanhui=(LinearLayout)findViewById(R.id.fanhui);
		mima=(EditText)findViewById(R.id.mima);
		mima1=(EditText)findViewById(R.id.mima1);
		finish=(Button)findViewById(R.id.finish);
		fanhui.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		Intent intent=getIntent();
		xiaoyanma=intent.getStringExtra("xiaoyanma");
		phone=intent.getStringExtra("phone");
		finish.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String txt = mima.getText().toString();
				String pxt = mima1.getText().toString();
				if(!txt.equals(pxt)){
					Toast.makeText(ForgetPasswordnextActivity.this, "密码输入不一致",Toast.LENGTH_SHORT ).show();
				}else{
					Map<String, String> map = new HashMap<>();
					map.put("xiaoyanma",xiaoyanma);
					map.put("password",mima.getText().toString());
					map.put("phone",phone);
					Gson gson=new Gson();
					String str=gson.toJson(map).toString();
					OkHttpUtils
							.post()
							.url(Config.url+"login/appupdPwd.do")
							.addParams("data",str)
							//.addParams("mobile","true")
							.build()
							.execute(new StringCallback() {
								@Override
								public void onError(Call call, Exception e, int id) {

								}

								@Override
								public void onResponse(String response, int id) {
								System.out.print("密码修改=="+response);
									if (response.equals("\"true\"")){
										Toast.makeText(ForgetPasswordnextActivity.this,"密码修改成功",Toast.LENGTH_SHORT).show();
										auto_login=(CheckBox)LoginActivity.instance.findViewById(R.id.cb_auto);
										auto_login.setChecked(false);
										if(LoginActivity.instance!=null){
											LoginActivity.instance.finish();
										}
										ForgetPasswordActivity.instance.finish();
										if(SafeSetActivity.instance!=null){
											SafeSetActivity.instance.finish();
										}
										if(MainFragmentActivity.instance!=null){
											MainFragmentActivity.instance.finish();
										}
										Intent intent=new Intent(ForgetPasswordnextActivity.this,LoginActivity.class);
										startActivity(intent);
										finish();
									}else {
										Toast.makeText(ForgetPasswordnextActivity.this,"密码修改失败",Toast.LENGTH_SHORT).show();
									}


								}
							});
				}
			}
		});

	}


}
